package com.h5;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/m")
public class H5Controller extends H5BaseController{

	@RequestMapping(method = RequestMethod.GET)
    public String defalut(){
    	return BASE_PATH+"/index";
    }
	
	@RequestMapping(value="index", method = RequestMethod.GET)
    public String index(){
    	return BASE_PATH+"/index";
    }
	
	@RequestMapping(value="category",method=RequestMethod.GET)
	public String category(){
		return BASE_PATH+"/category";
	}
	
	@RequestMapping(value="selectCity",method=RequestMethod.GET)
	public String selectCity(){
    	return BASE_PATH+"/city";
    }
	
	@RequestMapping(value="/s/{id}")
	public String index(@PathVariable("id")String id,ModelMap map){
		map.put("id", id);
		return BASE_PATH+"/store";
	}
	
	@RequestMapping(value="/goods/{id}")
	public String goods(@PathVariable("id")String id,ModelMap map){
		map.put("id", id);
		return BASE_PATH+"/storeTg";
	}
	@RequestMapping(value="/s/comment/{id}")
	public String storeComment(@PathVariable("id")String id,ModelMap map){
		map.put("id", id);
		return BASE_PATH+"/storeComment";
	}
	
	@RequestMapping("/actstore/{id}")
	public String storeact(@PathVariable("id")String id,ModelMap map){
		map.put("id", id);
		return BASE_PATH+"/storeComment";
	}
	@RequestMapping("/actgoods/{id}")
	public String goodsact(@PathVariable("id")String id,ModelMap map){
		map.put("id", id);
		return BASE_PATH+"/storeComment";
	}
	
	@RequestMapping(value="search", method = RequestMethod.GET)
    public String seacrh(){
    	return BASE_PATH+"/search";
    }	
	
	@RequestMapping(value="qianggou", method = RequestMethod.GET)
    public String qianggou(){
    	return BASE_PATH+"/quick";
    }	
	
	@RequestMapping(value = "creditMall",method=RequestMethod.GET)
	public String creditMall(){
		return BASE_PATH + "/creditMall";
	}
	
	@RequestMapping(value="credit",method=RequestMethod.GET)
	public String credit(){
		return BASE_PATH + "/creditMall";
	}
	
	@RequestMapping(value="credit/{id}",method=RequestMethod.GET)
	public String creditDetail(@PathVariable("id")String id,ModelMap map){
		map.put("id", id);
		return BASE_PATH + "/creditDetail";
	}
	
	@RequestMapping(value="logout", method = RequestMethod.GET)
	public String logout(HttpSession session, HttpServletRequest request, HttpServletResponse response){
		session.removeAttribute(SESSION_H5_USER);
		/*// 删除cookie缓存
		CookieUtil cu = new CookieUtil(request, response, -1);
		cu.deleteCookie("account");
		cu.deleteCookie("pwd");*/
    	return "redirect:/m/";
    }	
	
	@RequestMapping(value="getCode/{code}", method = RequestMethod.POST)
	@ResponseBody
	public String getCode(HttpSession session,@PathVariable String code) throws Exception{
		/*String string = codeService.getCode(code);
		Ret ret = new Ret();
		ret.setCode(0);
		ret.setMsg(string);
		return JSONUtils.serialize(ret);*/
		return null;
	}
	
	@RequestMapping(value="login", method = RequestMethod.GET)
    public String login(HttpSession session,HttpServletRequest request){
		Object obj = session.getAttribute(SESSION_H5_USER);
		if(obj!=null){
			return "redirect:/m/home";
		}
    	return BASE_PATH+"/login";
    }
	
	@RequestMapping(value="home")
	public String home(){
		return BASE_PATH+"/home";
	}
	@RequestMapping(value="setting")
	public String setting(){
		return BASE_PATH+"/setting";
	}
	
	@RequestMapping(value="regist", method = RequestMethod.GET)
	public String regist(HttpSession session,HttpServletRequest request){
		Object obj = session.getAttribute(SESSION_H5_USER);
		if(obj!=null){
			return "redirect:/m/home";
		}
		return BASE_PATH+"/regist";
	}
	@RequestMapping(value="registNext", method = RequestMethod.GET)
	public String registNext(HttpSession session,HttpServletRequest request){
		Object obj = session.getAttribute(SESSION_H5_USER);
		if(obj!=null){
			return "redirect:/m/home";
		}
		return BASE_PATH+"/registTwo";
	}
	
	@RequestMapping("/xiaofei")
	public String xiaofei(HttpSession session){
		Object obj = session.getAttribute(SESSION_H5_USER);
		if(obj==null){
			return "redirect:/m/login";
		}
    	return BASE_PATH+"/xiaofei";
	}
	@RequestMapping("/lipin")
	public String lipin(HttpSession session){
		Object obj = session.getAttribute(SESSION_H5_USER);
		if(obj==null){
			return "redirect:/m/login";
		}
		return BASE_PATH+"/lipin";
	}
	@RequestMapping("/visit")
	public String visit(HttpSession session){
		Object obj = session.getAttribute(SESSION_H5_USER);
		if(obj==null){
			//return "redirect:/m/login";
		}
		return BASE_PATH+"/myCollect";
	}
	@RequestMapping("/comment")
	public String comment(HttpSession session){
		Object obj = session.getAttribute(SESSION_H5_USER);
		if(obj==null){
			return "redirect:/m/login";
		}
		return BASE_PATH+"/myComment";
	}
	@RequestMapping("/message")
	public String message(HttpSession session){
		Object obj = session.getAttribute(SESSION_H5_USER);
		if(obj==null){
			return "redirect:/m/login";
		}
		return BASE_PATH+"/message";
	}
	@RequestMapping("/creditLog")
	public String creditLog(HttpSession session){
		Object obj = session.getAttribute(SESSION_H5_USER);
		if(obj==null){
			return "redirect:/m/login";
		}
		return BASE_PATH+"/creditLog";
	}
	@RequestMapping("/myCoupon")
	public String myCoupon(HttpSession session){
		Object obj = session.getAttribute(SESSION_H5_USER);
		if(obj==null){
			return "redirect:/m/login";
		}
		return BASE_PATH+"/myCoupon";
	}
	
}
